package other;

import org.springframework.context.annotation.Bean;

import javax.annotation.PostConstruct;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;


//@ImportAutoConfiguration(TestComponent4.class)
public class TestComponent1 {
    public TestComponent1() throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
        System.out.println("-----------------------------------------");
        System.out.println("TestComponent1 constructed");
        System.out.println("-----------------------------------------");
        Class<?> classForName = Class.forName("other.TestComponent4");
        Constructor<?> constructor = classForName.getConstructor(String.class);
        IComponent component4= (IComponent)constructor.newInstance("ssss");
        System.out.println("dynamic create instance of TestComponent4 successful");
        component4.doShit();
    }
    @PostConstruct
    public void init2()
    {
        System.out.println("-----------------------------------------");
        System.out.println("TestComponent1 @PostConstruct annotated method executed");
        System.out.println("-----------------------------------------");
    }

    public  void init()
    {
        System.out.println("-----------------------------------------");
        System.out.println("TestComponent1 init method executed");
        System.out.println("-----------------------------------------");
    }

    @Bean
    public  TestComponent3 component3()
    {
        return new TestComponent3();
    }
}
